//
// FileControlBlock.h
// Usage: Process FCB
// CreateDate: 2009-05-19
// Author: MaJiuyue
//
#ifndef _FILECONTROLBLOCK_H_
#define _FILECONTROLBLOCK_H_

#include <errno.h>
#include "FileSystem.h"
#include "File.h"
#include "Directory.h"

struct FileObject
{
	File * f_fd;
	int f_pos;
};

class FileControlBlock
{
private:
	// Process's root directory
	Directory * m_RootDir;
	// Process's working directory
	Directory * m_WorkingDir;
	// Process's open file table
	FileObject m_FileObjectTable[MAX_OPENFILE_NR];
	// Opened file NR
	int m_OpenFileNR;

public:
	FileControlBlock();
	FileControlBlock(const FileControlBlock &target);
	~FileControlBlock();

public:
	Directory * GetRootDirectory() { return m_RootDir; }
	void SetRootDirectory(Directory * root) { m_RootDir = root; }
	Directory * GetWorkingDirectory() { return m_WorkingDir; }
	void SetWorkingDirectory(Directory * dir) { m_WorkingDir = dir; }

	int open(const char * path);
	void close(int fd);
	int read(int fd, addr_t buf, size_t len);
	int write(int fd, addr_t buf, size_t len);
	int lseek(int fd, int offset, int whence);
};

#endif

